#include "StdAfx.h"
#include "SlowMotion.h"
#include <assert.h>

SlowMotion::SlowMotion(int instrNumber,MY_DATATYPE x,MY_DATATYPE y,MY_DATATYPE z):ConfigurationState(instrNumber)
{
	this->x = x;
	this->y = y;
	this->z = z;
}

SlowMotion::~SlowMotion(void)
{
}

void SlowMotion::perform(MillingMachine3C * machine,MillingTool * tool)
{
	assert(x>=0);
	assert(y>=0);
	assert(z>=0);

	x = x<0.0?0.0:x;
	y = y<0.0?0.0:y;
	//assert((UINT)x<machine->width);
	//assert((UINT)y<machine->height);

	x = x>(machine->width-1) ? (machine->width-1) : x;
	y = y>(machine->height-1) ? (machine->height-1) : y;
	tool->MoveTo(x,y,z);
	machine->SetValueAtWithoutFlushing((int)x,(int)y,z);
}

void SlowMotion::serialize(std::ostream & out)
{
	//ConfigurationState::serialize(out);
	out<<this->lineNumberChar<<this->number<<"G01X"<<this->x<<"Y"<<this->y<<"Z"<<this->z<<"\n\r";
}